var ua = window.navigator.userAgent;
var isIE = "ActiveXObject" in window;
var isChrome = ua.match(/Chrome/i);
var isMobile = !!(
  ua.match(/(iPhone|iPad|iPod)/i) ||
  ua.match(/Android/i) ||
  ua.match(/Windows Phone/i) ||
  ua.match(/IEMobile/i)
);
//android终端
var isAndroid = ua.indexOf("Android") > -1 || ua.indexOf("Adr") > -1;
var isiOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
var Sys = {};
var u = ua.toLowerCase();
var s;
(s = u.match(/msie ([\d.]+)/))
  ? (Sys.ie = s[1])
  : (s = u.match(/firefox\/([\d.]+)/))
  ? (Sys.firefox = s[1])
  : (s = u.match(/chrome\/([\d.]+)/))
  ? (Sys.chrome = s[1])
  : (s = u.match(/opera.([\d.]+)/))
  ? (Sys.opera = s[1])
  : (s = u.match(/version\/([\d.]+).*safari/))
  ? (Sys.safari = s[1])
  : 0;

var IEVersion = null;
var isIE8, isIE9, isIE10, isIE11;
isIE8 = isIE9 = isIE10 = isIE11 = false;
var appName = navigator.appName;
if (appName == "Microsoft Internet Explorer" || isIE) {
  var ret = ua.match(/MSIE (\d+[.\d]*)/);
  if (ret) {
    var version = ret[1];
    IEVersion = version;
    var num = parseInt(version, 10);
    isIE8 = num === 8;
    isIE9 = num == 9;
    isIE10 = num == 10;
    isIE11 = num == 11;
  }
}

/**
 * 浏览器环境判断模块
 */
export default {
  isChrome, // 是否Chrome浏览器
  isIE, // 是否IE浏览器
  isMobile, // 是否移动端
  isAndroid,
  isiOS,
  Sys,
  IEVersion,
  isIE8,
  isIE9,
  isIE10,
  isIE11,
};
